

/*#include "View.h"
#include "Matching.h"
#include "process.h"
#include "conio.h"
#include "stdlib.h"
#include "Reconstruction3D.h"
#include <stdio.h>
#include "StereoX/Stereo.h"
#using <mscorlib.dll>

 #include <string.h>  
 #include <iostream>  
 #include <sstream> 
#include "highgui.h" 
#include "Virtual.h" 


using namespace System;
using namespace Stereo;*/

#include "View.h"
#include "Matching.h"
#include <stdio.h>
#include "Reconstruction3D.h"

void main(){


	/*

	Matching m;
	m.setParameters(3,3,10,10,50,50,50);
	
	
	Reconstruction3D rec;

	CameraParameters cam=GlobalFunctions::CalibCamImages("calib/bureau/",30,cvSize(8,6),30.000);
	
	rec.Generate3DPoints2("experiment/expbureau/",1,52,m,cam);
	
	
	exit(0);
	*/
	
	// loading image
	View view1("img/im1.bmp");
	View view2("img/im2.bmp");
	

	// extracting corners
	view1.GetCorners();
	view2.GetCorners();

	// creating a Matching object
	Matching m;

	// setting search region size
	m.setSearchRegionSize(200,200);

	// setting template size
	m.setCorrelationWindowSize(10,10);

	// finding matches
	m.findAllBestMatches(view1,view2,3,3,50);

	// Mark the fisrt 100 match points 
	m.markMatchsWithNumbers(view1,view2,100);
	
	// to avoid outliers
	m.RefineMatching(1);
	
	// to visualise the match points moviment
	m.drawLines(view1);
	
	// Display image 
	view1.showImage();
	view2.showImage();
	view1.hold();
	view2.hold();

	
}	
	
	/* -----------Reconstrucao 3d Ambiente virtual--------------------
	
	
	CvPoint3D32f campos1= cvPoint3D32f(40,50,50);
	CvPoint3D32f campos2= cvPoint3D32f(70,50,50);
	
	Virtual vir(campos1,campos2);
	vir.Reconstruct3DPointsFromVirtualData();

	--------------------------------------------------*/
	
	
	
	
	
	
	// -----------Reconstrucao 3d de um video--------------------
	
	/*Reconstruction3D* rr=new Reconstruction3D();
	
	
	
	Matching m;
	m.setParameters(3,3,10,10,35,35,50);
	
	Reconstruction3D rec;

	
	CameraParameters cam=GlobalFunctions::CalibrateCamera("calib/calib3.avi",50,cvSize(8,60),30.0);
	
	
	rec.Generate3DPoints("video/inside_old1.avi",10,m,cam);
	
	exit(0);
	*/
	
	//---------------------------------------------------------------*/
	

	
	
	
	
	/* --------------------Manual test 2 imagens de um video-----------------------------
	
	
	CameraParameters cam=GlobalFunctions::CalibrateCamera("calib/calib.avi",50);
	
	CvCapture* capture = cvCaptureFromAVI("video/outside2.avi");
	
	IplImage* img = 0; 
	
		
		cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, 1550);
	    
		if(!cvGrabFrame(capture)){              // capture a frame 
			 printf("Could not grab a frame1 \n\7");
			 exit(0);
		}
		
		
		img=cvRetrieveFrame(capture);           // retrieve the captured frame
		//img=cvCloneImage(cvRetrieveFrame(capture));
		
      
		View cena1(img,1);
		//cena1.showImage();
		
	

		cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, 1560);
		
		if(!cvGrabFrame(capture)){              // capture a frame 
			 printf("Could not grab a frame2 \n\7");
			 exit(0);
		}
		
		img=cvRetrieveFrame(capture);           // retrieve the captured frame
		//img=cvCloneImage(cvRetrieveFrame(capture));
      
		View cena2(img,100);
		//cena2.showImage();
		
		
		// release video
		cvReleaseCapture(&capture);
	

	
	CvRect rect = cvRect(0,0,780, 580);
	CvPoint point = cvPoint(340,240);
	CvPoint points[5000];
   
	
	
	
	//View cena1("img/img1.bmp");
	//View cena2("img/img2.bmp");
	
	cena1.GetCorners();
	cena2.GetCorners();
	
	
	Matching m;
	m.setParameters(3,3,10,10,30,30,20);
	m.sizeMultplier=2;
	

	//m.setSearchRegionSize(150,150);
	//m.setCorrelationWindowSize(10,10);

	//cena1.setInterestPoints(rect);
	
	// m.setPointsInSearchRegion(cena1.CornerPoints[0],cena1);
	//m.setPointsInSearchRegion(point,cena2);
	
	//cena1.printValuePoints(10);
	
	//cena2.markInterestPoints();
	//cena1.printValuePoints(10);
	//m.findBestMatch(cena1.interestPoints[0],cena1,cena2);
	


	//printf(" value best point(%i,%i) %f\n ",cena1.CornerPoints[0].x,cena1.CornerPoints[0].y,cena1.cornerValues[0]);
	//printf(" value best interest point (%i,%i) \n ",cena1.interestPoints[0].x,cena1.interestPoints[0].y);
	
	m.findAllBestMatches(cena1,cena2,5,5,50);
	m.markMatchsWithNumbers(cena1,cena2,m.matchPointsNumber);
	m.RefineMatching(1);
	
	m.drawLines(cena1);

	//exit(0);

	StereoMatcher st;
  
	// get parameters from calibration

	st.SetCamerasParameters(cam,cam);

	
	st.Load2dPoints(m.matchPointsScene1,m.matchPointsScene2);
	
	
	
	CvMat *rMat=cvCreateMat(3,3,CV_64F);
	CvMat *r=cvCreateMat(3,1,CV_64F);
	CvMat *T=cvCreateMat(3,1,CV_64F);
	CvMat *essential=cvCreateMat(3,3,CV_64F);
	CvMat *fund=cvCreateMat(3,3,CV_64F);

	st.Analyse();
	
	st.GetGoodRightProjectionMatrix(rMat, r, T, essential, fund);
   // st.DrawCorrespondingEpilines(cena1.img,cena2.img);
	


	//cena1.markPoint(cena1.CornerPoints[0]);
	//cena1.markInterestPoints();
	


	cena1.showImage();
	cena2.showImage();
	cena1.hold();
	cena2.hold();


*/

	//Object *o=new Object();
	//Object os;
	//delete o;
	
	
	
	
	
//}